﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using DevExpress.XtraGrid.Columns;
using System.Reflection;
using Ebada.Client;
using DevExpress.XtraGrid.Views.Base;
using Ebada.Client.Platform;
namespace Ebada.Modules.Vehicle
{

    public partial class UCVehicleParts : DevExpress.XtraEditors.XtraUserControl {
        private GridViewOperation<VehicleParts> gridViewOperation;

        public event SendDataEventHandler<VehicleParts> FocusedRowChanged;
        public static bool FirstLoad = false;
        public string VehicleID = "";
        public UCVehicleParts() 
        {
            InitializeComponent();
           // initColumns();
            gridViewOperation = new GridViewOperation<VehicleParts>(gridControl1, gridView1, barManager1,new frmVehiclePartsEdit());
            gridViewOperation.CreatingObjectEvent +=gridViewOperation_CreatingObjectEvent;
            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridViewOperation_FocusedRowChanged);
            gridViewOperation.BeforeAdd += new ObjectOperationEventHandler<VehicleParts>(gridViewOperation_BeforeAdd);
            gridViewOperation.AfterAdd += new ObjectEventHandler<VehicleParts>(gridViewOperation_AfterAdd);
            InitData();
        }

        void gridViewOperation_AfterAdd(VehicleParts obj)
        {
            InitData();
        }

        void gridViewOperation_BeforeAdd(object render, ObjectOperationEventArgs<VehicleParts> e)
        {
            
            e.Value.VehicleID = VehicleID;
        }

        void gridViewOperation_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) 
        {
            if (FocusedRowChanged != null)
                FocusedRowChanged(gridView1, gridView1.GetFocusedRow() as VehicleParts);
        }
        


       
        /// <summary>
        /// 设置隐藏列
        /// </summary>
        /// 
       public  void initColumns() 
        {
            
          
        }
      
    
        /// <summary>
        /// 封装了数据操作的对象
        /// </summary>
        [Browsable(false)]
       public GridViewOperation<VehicleParts> GridViewOperation
       {
            get { return gridViewOperation; }
            set { gridViewOperation = value; }
        }
        /// <summary>
        /// 新建对象设置Key值
        /// </summary>
        /// <param name="newobj"></param>
        void gridViewOperation_CreatingObjectEvent(VehicleParts newobj)
        {
            //newobj.VehicleID = Guid.NewGuid().ToString();
           
        }
       
        public void InitData()
        {
            gridViewOperation.RefreshData("");
        }
        /// <summary>
        /// 根据当前选择的车辆ID查看备品情况
        /// </summary>
        /// <param name="VehicleID"></param>
        public void RefreshData(string VehicleID)
        {
            gridViewOperation.RefreshData(" where VehicleID='" + VehicleID + "'");
        }

    }
}
